import React, { useState } from 'react';
import { IFormItem, Itype } from '@/base-ui/form';
import http from '@/services/request';
import { Space, Button, Select } from 'antd';
import { Input } from 'antd';
import { RightOutlined, UpOutlined } from '@ant-design/icons';

const { Option } = Select;

const { Search } = Input;

/* 搜索区域 */
// 这是高级检索的搜索配置项，一般要和你的表格的列关联
export const PageSearchConfig: IFormItem[] = [
  {
    type: 'input' as Itype,
    label: '总车辆数量',
    name: 'allCarNumber',
    placeholder: '请输入总车辆数量'
  },
  {
    type: 'input' as Itype,
    label: '空闲车辆数量',
    name: 'freeCarNumber',
    placeholder: '请输入空闲车数量'
  },
  {
    type: 'input' as Itype,
    label: '忙碌车辆数量',
    name: 'busyCarNumber',
    placeholder: '请输入忙碌车辆数量	'
  },
  {
    type: 'input' as Itype,
    label: '维修车辆数量',
    name: 'maintainCarNumber',
    placeholder: '请输入维修车辆数量'
  },
  {
    type: 'input' as Itype,
    label: '产权所属单位',
    name: 'propertyRightUnit',
    placeholder: '请输入产权所属单位'
  },
  {
    type: 'input' as Itype,
    label: '管理员名字',
    name: 'managerName',
    placeholder: '请输入管理员名字'
  },
  {
    type: 'input' as Itype,
    label: '管理员电话',
    name: 'managerPhone',
    placeholder: '请输入管理员电话'
  },
  {
    type: 'input' as Itype,
    label: '车库名称',
    name: 'garageName',
    placeholder: '请输入车库名称'
  },
  {
    type: 'input' as Itype,
    label: '车库面积',
    name: 'garageArea',
    placeholder: '请输入车库面积'
  },
  {
    type: 'input' as Itype,
    label: '车库容量',
    name: 'garageCapacity',
    placeholder: '请输入车库容量'
  },
  {
    type: 'input' as Itype,
    label: '备注',
    name: 'remark',
    placeholder: '请输入备注'
  }
];

//高级检索
export const UseSearch = (props: any) => {
  return (
    <Space style={{ float: 'right' }}>
      {props.isMoreSearchShow ? (
        <Button
          type="link"
          size="large"
          onClick={() => {
            props.setisMoreSearchShow(false);
            props.setsearchMore(false);
          }}
        >
          收起
          <UpOutlined />
        </Button>
      ) : (
        <Button
          type="link"
          size="middle"
          onClick={() => {
            props.setisMoreSearchShow(true);
            props.setsearchMore(true);
          }}
        >
          高级检索
          <RightOutlined style={{ marginLeft: '1px' }} />
        </Button>
      )}
    </Space>
  );
};

// 这里是模糊查询 根据xxx进行查询
export const SearchSelector = (props: any) => {
  const [searchid, setsearchid]: any = useState('managerName');
  return (
    <div
      style={{
        display: 'inline-block',
        width: '380px',
        marginBottom: 10,
        marginRight: 10,
        float: 'right'
      }}
    >
      <Select
        defaultValue={Options[1].label}
        style={{ width: 100 }}
        defaultActiveFirstOption
        onSelect={(value: string, option: any) => {
          setsearchid(option.key);
        }}
      >
        {Options.map((i) => (
          <Option value={i.label} key={i.value} children={null} />
        ))}
      </Select>
      <Search
        placeholder="请输入您要查的数据"
        onSearch={(e) => {
          // console.log(e);
          // console.log(searchid);
          if (e.trim() === '') {
            http.get('/logistics/carManagementLogistics/get/1/10').then((res) => {
              props.dataSource(res.data.records);
            });
            return;
          }
          switch (searchid) {
            case 'managerName': {
              http(`/logistics/carManagementLogistics/list/managerName/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            case 'managerPhone': {
              http(`/logistics/carManagementLogistics/list/managerPhone/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            // case 'id': {
            //   http(`/logistics/dispatchOrderLogistics/get/${e}`).then((res) => {
            //     props.dataSource([res.data]);
            //   });
            //   break;
            // }
            default: {
              break;
            }
          }
        }}
        style={{ width: '280px' }}
        enterButton
      />
    </div>
  );
};
export const Searchdow = () => {
  return;
};

const Options = [
  { label: '管理员名字', value: 'managerName', onClick: (e: any) => {} },
  { label: '管理员联系电话', value: 'managerPhone', onClick: (e: any) => {} },
  // { label: 'ID', value: 'id', onClick: (e: any) => {} }
];

/* 表格区域 */

//复选框的接口
export interface DataType {
  id: number;
  key: React.Key;
  name: string;
  age: number;
  address: string;
}
